package com.example.yuejianapp14.Activity.Model;

import com.example.yuejianapp14.Activity.JavaBean.Act;
import com.example.yuejianapp14.Activity.JavaBean.Coach;
import com.example.yuejianapp14.Activity.JavaBean.Coachask;
import com.example.yuejianapp14.Activity.Listener.ClubNoListListener;
import com.example.yuejianapp14.Activity.Listener.CoachListener;
import com.example.yuejianapp14.Activity.Listener.CoachaskListener;
import com.example.yuejianapp14.Activity.Servics.ActService;
import com.example.yuejianapp14.Activity.Servics.CoachService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 张森 on 2017/9/25.
 */

public class CoachModel {
    private Retrofit retrofit;
    private String BASEURL ="http://10.0.2.2/YueJian/index.php/Api/Coach/";
    private String HeadPhotoNameDefault="user_headphoto.png";

    public CoachModel(){
        retrofit= new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }



    public void coachask(String askid,final CoachaskListener listener){
        CoachService coachServic=retrofit.create(CoachService.class);
        Call<List<Coachask>> call=coachServic.coachask(askid);
        call.enqueue(new Callback<List<Coachask>>() {
            @Override
            public void onResponse(Call<List<Coachask>> call, Response<List<Coachask>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                }else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<Coachask>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }








    public void getCoachList(final CoachListener listener){
        CoachService coachServic=retrofit.create(CoachService.class);
        Call<List<Coach>> call=coachServic.getCoach();
        call.enqueue(new Callback<List<Coach>>() {
            @Override
            public void onResponse(Call<List<Coach>> call, Response<List<Coach>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }
            @Override
            public void onFailure(Call<List<Coach>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });


    }
    public void findCoach(String clubid,final CoachListener listener){
        CoachService coachServic=retrofit.create(CoachService.class);
        Call<List<Coach>> call=coachServic.findCoach(clubid);
        call.enqueue(new Callback<List<Coach>>() {
            @Override
            public void onResponse(Call<List<Coach>> call, Response<List<Coach>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                }else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<Coach>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }


    public void coachinfo (String coachid,final ClubNoListListener listener){
        CoachService coachService=retrofit.create(CoachService.class);
        Call call = coachService.coachinfo(coachid);
        Callback<Coach> callback =new Callback<Coach>() {
            @Override
            public void onResponse(Call<Coach> call, Response<Coach> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                }else
                    listener.onFail("onresponse fail");

            }

            @Override
            public void onFailure(Call<Coach> call, Throwable t) {

            }
        };
        call.enqueue(callback);
    }


}
